﻿using System;

namespace IupNET
{
    public class Point2d
    {
        public readonly double X;
        public readonly double Y;

        public Point2d(double x, double y)
        {
            X = x;
            Y = y;
        }


        public Point2d(Point2d tocopy)
        {
            X = tocopy.X;
            Y = tocopy.Y;
        }

        public Point2d Transform(Matrix2d matrix)
        {
            return new Point2d(
                X * matrix.M[0] + Y * matrix.M[2] + matrix.M[4],
                X * matrix.M[1] + Y * matrix.M[3] + matrix.M[5]
            );
        }


        public static bool TryParse(string str, out Point2d res)
        {
            res = null;
            string[] xy = str.Split(',');
            if (xy.Length != 2)
                return false;
            double x, y;
            if (!double.TryParse(xy[0], out x))
                return false;
            if (!double.TryParse(xy[1], out y))
                return false;
            res = new Point2d(x, y);
            return true;
        }

    }
}
